var utils = require("../../../../utils/util.js");
Page({
  data: {
    curText:'',
    level: 0,
    curItem:{},
    curItemId:-1,
    radioItems: [
      { name: '高', value: '1'},
      { name: '中', value: '2' },
      { name: '低', value: '3' },
      { name: '计划', value: '4' }
    ]
  },
  onShow: function () {
    let curId = wx.getStorageSync('curId');
    if (typeof curId == 'undefined'){
      wx.showToast({
        title: '不存在该事项！',
        icon: 'none',
        duration: 2000
      });
      setTimeout(function(){
        wx.navigateBack({});
      },2000);
    }else{
      let itemList = wx.getStorageSync('itemList') || [];
      this.setData({
        curItem: itemList[curId],
        curItemId: curId
      });
    };
  },
  formSubmit: function (event) {
    let msg = event.detail.value;
    let curItem = this.data.curItem;
    let curId = this.data.curItemId
    let itemList = wx.getStorageSync('itemList') || [];
    let newList;
    if (msg.title == curItem.title && msg.level == curItem.level){
      //没有修改，不做操作
    }else{
      itemList.splice(curId, 1, { id: curId,title:msg.title,level:msg.level});
      itemList = utils.dealItemList(itemList);
      wx.setStorageSync('itemList', itemList);
    }
    wx.navigateBack({});
  },
  formReset: function () {
    wx.navigateBack({}); 
  }
})